import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver import ActionChains

options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(options=options)
# driver = webdriver.Chrome()
driver.maximize_window()


#注册
# driver.get("http://127.0.0.1/index.php")
# driver.find_element(By.LINK_TEXT,'注册').click()
# driver.find_element(By.ID,'username').send_keys('18325539630')
# driver.find_element(By.CLASS_NAME,'J_imgcode').send_keys('8888')
# driver.find_element(By.ID,'password').send_keys('wsf123456')
# driver.find_element(By.ID,'password2').send_keys('wsf123456')
# driver.find_element(By.NAME,'invite').send_keys('18325539630')
# driver.find_element(By.CLASS_NAME,'J_btn_agree').click()
#
# WebDriverWait(driver,9,1).until(lambda
# x:x.find_element(By.CLASS_NAME,'layui-layer-btn0')).click()


#登录
driver.get("http://127.0.0.1/index.php/Home/user/login.html")
driver.find_element(By.ID,'username').send_keys('18325539630')
driver.find_element(By.ID,'password').send_keys('wsf123456')
driver.find_element(By.ID,'verify_code').send_keys('8888')
driver.find_element(By.NAME,'sbtbutton').click()


WebDriverWait(driver,5,0.5).until(lambda
x:x.find_element(By.LINK_TEXT,'返回商城首页')).click()

js = "window.scrollTo(0, 1000)"
driver.execute_script(js)
aa='a[href="/Home/Goods/goodsInfo/id/65.html"] div[class="googs-title ellipsis-1"]'
name01=driver.find_element(By.CSS_SELECTOR,aa)


ele="div[class='goods-pic'] img[src='/public/upload/goods/thumb/65/goods_thumb_65_400_400.jpeg']"
element=driver.find_element(By.CSS_SELECTOR,ele)

# 创建鼠标对象
action = ActionChains(driver)
# 调用鼠标双击事件方法
action.double_click(element)
# 调用鼠标执行方法
action.perform()

driver.find_element(By.CLASS_NAME,'add').click()

#点击加入购物车

driver.find_elements(By.ID,'join_cart')[0].click()

# name2=driver.find_element(By.CSS_SELECTOR,'div[class="detail-ggsl"] h1').text


WebDriverWait(driver,5,0.5).until(lambda
x:x.find_element(By.CLASS_NAME,'layui-layer-ico')).click()

number=driver.find_element(By.ID,'cart_quantity').text
print(number)
#进入我的购物车
driver.find_element(By.CSS_SELECTOR,'div[class="c-n fl"] span').click()
#获取商品金额
# tt=driver.find_element(By.CSS_SELECTOR,'tr[class="item-single"] td[id="cart_23_market_price"]').text


#清楚购物车

driver.find_element(By.CSS_SELECTOR,
                    'td[align="center"] a[class="gwc-gb deleteGoods"]').click()
#driver.find_element(By.ID,'removeGoods').click()
# amount=a[1:]
# print(amount)